home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6192 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  29 lines

  1. Path: keats.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP IN WRITING MY FIRST PROGRAM ASSINGMENT
  5. Date: 22 Feb 1996 12:44:54 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4gikk6INNjiv@keats.ugrad.cs.ubc.ca>
  8. References: <3127dd4f.19010083@news.planet.net>
  9. NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
  10.  
  11. In article <3127dd4f.19010083@news.planet.net>,
  12. David <cygnusx@planet.net> wrote:
  13. >I have to write a program that uses a array, reads a value and puts
  14. >all the values in ascending order and then print it out. array size
  15. >100 values . any ideas ?? will be grateful.
  16.  
  17. This reads string values, until you hit Ctrl-D (or whatever your terminal
  18. system uses to mean "EOF") and sorts them lexicographically.
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. int main(){int i,j;char x[256],*y[100];for(i=0;i<100&&fgets(x,256,stdin);i++)
  24. i[y]=strdup(x);qsort(y,i,sizeof(char*),(int(*)(const void*,const void*))strcmp);
  25. for(j=0;j<i;j++)fputs(j[y],stdout);return 0;}
  26.  
  27. -- 
  28.  
  29.